package utils;

import java.util.Locale;
import java.util.ResourceBundle;

import config.Parameters;

public class MessageUtils {

	public static String getI18n(String key) {
		return getMessage(Parameters.MSG, key);
	}

	public static String getI18nAppLong(String key) {
		return getMessage(Parameters.MSG_APP_LONG, key);
	}

	public static String getMessage(String messagePackage, String key, Locale lc) {
		ResourceBundle msgs = ResourceBundle.getBundle(messagePackage, lc);
		return msgs.getString(key);
	}

	private static String getMessage(String messagePackage, String key) {

		// si no troba la traduccio posara la clau

		String msg = key;
		Locale lc = SessionUtils.getSessionLocale();
		try {
			ResourceBundle msgs = ResourceBundle.getBundle(messagePackage, lc);
			msg = msgs.getString(key.toLowerCase());
		} catch (Exception e) {
			System.out.println("no sa trobat " + key + " " + messagePackage);
		}
		return msg;
	}
}
